package crp.core.department.domain.repositories;

import com.qwlabs.lang.C2;
import crp.core.department.domain.models.DepartmentEntity;
import io.quarkus.hibernate.orm.panache.PanacheQuery;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Parameters;

import javax.enterprise.context.ApplicationScoped;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Stream;

import static io.quarkus.panache.common.Parameters.with;

@ApplicationScoped
public class DepartmentRepository implements PanacheRepositoryBase<DepartmentEntity, String> {

    public Optional<DepartmentEntity> findByCode(String code) {
        return find("code=:code", with("code", code))
                .firstResultOptional();
    }

    public Stream<DepartmentEntity> findByIds(Collection<String> ids) {
        if(C2.isEmpty(ids)){
            return Stream.empty();
        }
        return find("id in (:ids)", Parameters.with("ids", ids)).stream();
    }
}
